'use strict';

const RouterService = require('../base');

class BannerService extends RouterService {
  static get modelName() {
    return 'Business.Address';
  }

  async beforeCreate(data) {
    if (data.status === 1) {
      // 将其他地址状态设置为0
      await this.model.update({
        status: 0
      }, {
        where: {
          user_id: data.user_id,
        }
      })
    }
    return true
  }

  async beforeUpdate(id, data) {
    if (data.status === 1) {
      // 将其他地址状态设置为0
      await this.model.update({
        status: 0
      }, {
        where: {
          user_id: data.user_id,
        }
      })
    }
    return data
  }
}

module.exports = BannerService;
